$(function(){
	//初始化 
	onlineConsultationDoctor();
	var archives_info_key =JSON.parse(sessionStorage.getItem("archives_info_key"));
	if(archives_info_key!=null){
		$(".archivesid").val(archives_info_key.archivesId);
		$("#choiceUser").text(archives_info_key.name);
	}
	var doctorid =utilModule.getQueryString("doctorId");
	sessionStorage.setItem("doctorid_info_key",JSON.stringify(doctorid));
	$(".doctorid").val(doctorid);
	$(".isUntoward input").on("click",initChecked);
	$(".isMedicine input").on("click",initChecked);
	function initChecked(){
		var t = $("input[name='istake']:checked").val();
		var y = $("input[name='isreflection']:checked").val();
		if(y!=0){
			if(t==0){
				mui.alert("此项不可选");
				return false;
			}
		}
		if(t==0){
			if(y!=0){
				mui.alert("此项不可选");
				return false;
			}
		}
	}
	$(".isAllergy input").on("click",function(){
	 var m = $("input[name='isallergy']:checked").val()
	 console.log(m);
		if(m==0){
			$("#allergyRemarks").hide();
		}else{
			$("#allergyRemarks").show();
		}
	});
	
	$("#allergyRemarks input").on("blur",function(){
		var allergydrugsText = $(this).val();
		console.log(allergydrugsText);
		var leng = allergydrugsText.length;
		if(leng*1>16){
			mui.alert("最多输入16字",'提示');
			$("#allergyRemarks input").focus();
			return;
		};	
	})
	//医生列表渲染
	function onlineConsultationDoctor(){
		var ysId =utilModule.getQueryString("doctorId");
		var param = {"doctorId":ysId};
		function callBackSlider(data){
			console.log(data);
			var html = '';
			html +='<div class="font3"><img src="'+data.doctor.avatar+'" />'+data.doctor.realname+'<p>'+data.doctor.hospitalName+'</p><p>'+data.doctor.deptName+'</p></div>';
			$(".medication-user").empty();
			$(".medication-user").append(html);
		}
		onlineContinuationModule.onlineDoctorDetail(param,callBackSlider);
	}
	
	//	图片上传
	$(".camera-area").fileUpload({
		"upload_url": "/att/upload", //上传url
		"remove_url": "/att/delete", //删除url
		"file": "file",
		"all": false, //是否启用压缩 
		"inputName": "questionfiles", //后台Vo对应的属性,
		"complete": function(response, inputID) {
			if(response.status == 200) {
			   //创建input元素
				var inputElement="<input type='hidden' name='filesurl' id='"+inputID+"' value='"+response.result.fullurl+"' key='"+response.result.filekey+"'/>";
				$("."+inputID).append(inputElement);
				//隐藏进度条
				$("#shadow_"+inputID).hide();
				console.info("文件路径:"+response.result.fullurl);
				console.info("文件key:"+response.result.filekey);
			} else {
				console.error("文件上传失败!");
			}	
		}
	});
	
	var questionfilesObject=$("input[name='filesurl']").length;
	var questionfiles=""; 
	    $("input[name='filesurl']").each(function(){
	    	questionfiles+=$(this).val()+",";
		});
	$("input[name='filesurl']").val(questionfiles);
	
	$("#choiceUser").on("click",function(){
		sessionStorage.setItem("skipType",3);	
		location.href="../../html/service/user-archives-list.html";
	});
	$(".submitOrder").on("click",function(){
		if($("input[name='drugsname']").val()==""){
			mui.alert("请输入药品名称")
			return false
		}
		if($("input[name='disease']").val()==""){
			mui.alert("请输入所患疾病")
			return false
		}
		if($("textarea").val()==""){
			mui.alert("请输入说明")
			return false
		}
		var param =$("#submitOrder").serialize()+"&userid="+USERID;
		console.log(param);
		function callBackSlider(data){
			console.log(data);
			if(utilModule.checkUndefined(data.status)==""){
				mui.alert("下单成功",function(){
					location.href="../../html/inquiry/message-list.html";
				})
			}else{
				mui.alert(data.msg);
				return false;
			}

		}
		onlineContinuationModule.submitOrder(param,callBackSlider);
	});	
});
